package site.zhouinfo.SingletonPattern;

class Instance {
    private Instance() {
    }

    public static Instance getSelf() {
        return new Instance();
    }
}

//懒汉式
class LSingle {
    private static Instance _instance = null;

    private LSingle() {
    }

    public static Instance getInstance() {
        if (_instance == null) {
            synchronized (LSingle.class) {
                _instance = Instance.getSelf();
            }
        }
        return _instance;
    }
}

//饿汉式
class ESingle {
    private static Instance _instance = Instance.getSelf();

    private ESingle() {
    }

    public static Instance getInstance() {
        return _instance;
    }
}
